As a configuration of a rotary encoder, a configuration in which a substrate provided with a light-emitting element that emits light and a substrate provided with a light-receiving element that detects the light emitted from the light-emitting element are housed in housing of the rotary encoder is known (for example, Patent Literature 1).